package com.guigu.basedservice.listener;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.alibaba.excel.metadata.CellData;
import com.guigu.basedservice.entity.BasePartsType;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @Author: janecraft
 * @Date: 2024/9/26
 * @Description: com.guigu.demo
 * @Version： 1.0
 */
public class PageReadListener extends AnalysisEventListener<BasePartsType> {

    private List<BasePartsType> list = new ArrayList<>();

    @Override
    public void invoke(BasePartsType basePartsType, AnalysisContext analysisContext) {
        System.out.println("===========" + basePartsType);
        list.add(basePartsType);
    }

    // 读取完成之后执行
    @Override
    public void doAfterAllAnalysed(AnalysisContext analysisContext) {
        System.out.println("end");
        System.out.println("读取完成, 数据量: " + list.size());
        for (BasePartsType item : list) {
            System.out.println(item);
        }
    }

    @Override
    public void invokeHead(Map<Integer, CellData> headMap, AnalysisContext context) {
        System.out.println("表头信息：" + headMap);
    }

    public List<BasePartsType> getList() {
        return list;
    }

    public void setList(List<BasePartsType> list) {
        this.list = list;
    }
}
